package signAction;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionContext;

import signBean.AdminDbManager;

public class AdminLessonAction {


	private List list;
	private int ipage=5;
	private int allpage;
	private int pages=0;
	 
	public String execute(){
		AdminDbManager ad = new AdminDbManager();
		list = ad.getLessons();
		List li1 = new ArrayList();
		try {
			int allpp = list.size();
			allpage = (int) (allpp + ipage - 1) / ipage;
			if (pages == 0) {
				pages = 1;
			} else {
				pages = getPages();
			}
			int spage = (pages - 1) * ipage;
			int num = spage + ipage;
			if (num > allpp)
				num = allpp;
			for (int j = spage; j < num; j++) {
				li1.add(list.get(j));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		setList(li1);
		setPages(pages);
		setAllpage(allpage);
		ActionContext.getContext().getSession().put("pages", pages);
		ActionContext.getContext().getSession().put("allpage", allpage);
		return "listlesson";
	}
	
	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public int getIpage() {
		return ipage;
	}

	public void setIpage(int ipage) {
		this.ipage = ipage;
	}

	public int getAllpage() {
		return allpage;
	}

	public void setAllpage(int allpage) {
		this.allpage = allpage;
	}

	public int getPages() {
		return pages;
	}

	public void setPages(int pages) {
		this.pages = pages;
	}
	
}
